What is the parent() method usage in jQuery?
parent() method usage in jQuery
250
28-Jul-2021
Aryan Kumar
26-Nov-2023In jQuery, the parent() method is used to traverse up the DOM hierarchy and select the parent element of the matched set of elements. It returns a set containing the unique ancestors of each element in the original set, optionally filtered by a selector.
Syntax:
Example:
In this example:
Keep in mind that parent() only selects the immediate parent. If you want to traverse up multiple levels, you can chain multiple parent() calls or use the parents() method with an optional filter.